home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / ANSIshellƒ / os_mac_eStyle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-18  |  23.1 KB  |  805 lines  |  [TEXT/R*ch]

  1. /* os_mac_eStyle.c
  2.  * 2Jun92  e
  3.  */
  4.  
  5. #ifdef THINK_C
  6. #include <MacHeaders>
  7. #else
  8. #ifdef __MWERKS__
  9. #else
  10. "Unknown compiler!"
  11. #endif
  12. #endif
  13.  
  14. /*
  15. #include <Dialogs.h>
  16. #include <Controls.h>
  17. #include <QuickDraw.h>
  18. #include <Windows.h>
  19. #include <ToolUtils.h>
  20. #include <OSUtils.h>
  21. #include <Menus.h>
  22. #include <Fonts.h>
  23. #include <resources.h>
  24. */
  25.  
  26. #include "os_mac.h"
  27.  
  28. /* extensions to an editor for text files by e
  29.    questions/comments via Internet <e@Flavors.COM>
  30. */
  31. /* Copyright © e 1992. All rights reserved.
  32.     Developed using THINK C 5.0.1 for use with Gambit Scheme.
  33.     This code may be freely distributed as long as this notice remains.
  34. */
  35.  
  36. /* to do:
  37. 06Jun92  e
  38. consider checkbox to modify OK to:
  39. - Set Style for All Windows
  40. consider showing text in style
  41. - (let ((the 3) (quick 5) (brown 7)) (fox jumps over the lazy dog))
  42. - ((lambda (the quick brown) (fox jumps over (the lazy) dog)) 3 5 7)
  43. consider a way to save Window's style in the file
  44. consider a way to save Creation style (preferences)
  45. add a Use Outline Fonts checkbox
  46. */
  47.  
  48. #define MAXFONTSIZE 1023
  49.  
  50. /* resources */
  51.  
  52. #define esdID        357
  53.  
  54. /* dialog items */
  55.  
  56. #define esdOK         1
  57. #define esdCancel     2
  58. #define esdTabsEt     3
  59. #define esdTabsSt     4
  60. #define esdFont1St     5
  61. #define esdFont1Pu     6
  62. #define esdSize1St     7
  63. #define esdSize1Et     8
  64. #define esdBold1Cb     9
  65. #define esdItal1Cb    10
  66. #define esdCond1Cb    11
  67. #define esdUndr1Cb    12
  68. #define esdInvr1Cb    13
  69. #define esdExpd1Cb    14
  70. #define esdFont2St    15
  71. #define esdFont2Pu    16
  72. #define esdSize2St    17
  73. #define esdSize2Et    18
  74. #define esdBold2Cb    19
  75. #define esdItal2Cb    20
  76. #define esdCond2Cb    21
  77. #define esdUndr2Cb    22
  78. #define esdInvr2Cb    23
  79. #define esdExpd2Cb    24
  80. #define esdPS1St    25
  81. #define esdPS2St    26
  82. #define esdSize1Pu    27
  83. #define esdSize2Pu    28
  84. #define esdOutline1    29
  85. #define esdOutline2    30
  86. #define esdOKring    31
  87. #define esdThisBt    32
  88. #define esdPrefBt    33
  89. #define esdDfltBt    34
  90. #define esdGetSt    35
  91. #define esdOutline3    36
  92. #define esdApplSt    37
  93. #define esdThisCb    38
  94. #define esdPrefCb    39
  95. #define esdWrapEt    40
  96. #define esdAutoInd    42
  97.  
  98. /* the pop-up font item */
  99.  
  100. /* See: Apple Macintosh Developer Technical Support
  101.         Pop-up Menu Example Application
  102.         PopMenus.p
  103. */
  104.  
  105. static TextStyle tsNewPri, tsNewAlt;
  106. static short tabsNew;
  107. static short wrapNew;
  108. static short autoIndNew;
  109.  
  110. #define popMenuID1 128
  111. static MenuHandle popMenu1;
  112. static Rect  popUpBox1;        /* boundsrect of font popUp1 */
  113. static Rect  promptBox1;    /* boundsrect of its title */
  114. static short fontChoice1;    /* its last chosen item */
  115.  
  116. #define popMenuID2 129
  117. static MenuHandle popMenu2;
  118. static Rect  popUpBox2;        /* boundsrect of font popUp2 */
  119. static Rect  promptBox2;    /* boundsrect of its title */
  120. static short fontChoice2;    /* its last chosen item */
  121.  
  122. #define popMenuID3 130
  123. static MenuHandle popMenu3;
  124. static Rect  popUpBox3;        /* boundsrect of font popUp2 */
  125. static short sizeChoice3;    /* its last chosen item */
  126.  
  127. #define popMenuID4 131
  128. static MenuHandle popMenu4;
  129. static Rect  popUpBox4;        /* boundsrect of font popUp2 */
  130. static short sizeChoice4;    /* its last chosen item */
  131.  
  132. /* some user item action procs -- used in update events mostly */
  133.  
  134. #define leftSlop 15
  135. #define rightSlop 17
  136. #define botSlop 5
  137.  
  138. static void drawPopArrow( Rect r )
  139.   FrameRect( &r );
  140.   MoveTo( r.right, r.top+2 );
  141.   LineTo( r.right, r.bottom );
  142.   LineTo( r.left+2, r.bottom );
  143.   MoveTo( r.right-17, r.top+6 );
  144.   Line( 11, 0 );
  145.   Move( -10, 1 );
  146.   Line( 9, 0 );
  147.   Move( -8, 1);
  148.   Line( 7, 0 );
  149.   Move( -6, 1);
  150.   Line( 5, 0 );
  151.   Move( -4, 1 );
  152.   Line( 3, 0 );
  153.   Move( -2, 1 );
  154.   Line( 1, 0 );
  155. }
  156.  
  157. static pascal void DrawPopUpSz( DialogPtr dwind, short dinum )
  158. { short itemtype;
  159.   Handle itemhandle;
  160.   Rect r;
  161.   GetDialogItem( dwind, dinum, &itemtype, &itemhandle, &r );
  162.   InsetRect( &r, -1, -1 );
  163.   drawPopArrow( r );
  164. }
  165.  
  166. static void DrawPopUpX( MenuHandle popMenu, Rect* popUpBox, short lastChoice )
  167. { Rect r;
  168.   Str255 curFont;
  169.   short newWid, newLen, wid;
  170.  
  171.   GetMenuItemText( popMenu, lastChoice, curFont ); /* get currently-selected item */
  172.   r = *popUpBox;
  173.   EraseRect( &r );
  174.   InsetRect( &r, -1, -1 );
  175.   /* Make sure the title fits. Truncate it and add an ellipses (“…”) otherwise */
  176.   wid = (r.right - r.left) - (leftSlop + rightSlop);
  177.   newWid = StringWidth( curFont );
  178.   if( newWid > wid )
  179.   { newLen = curFont[0]; /* current length in characters */
  180.     wid = wid - CharWidth('…');
  181.     do
  182.     { newWid = newWid - CharWidth( curFont[newLen--] );
  183.     } while( ( newWid > wid ) && ( newLen > 0 ) );
  184.     curFont[++newLen] = '…';
  185.     curFont[0] = newLen;
  186.   }
  187.   drawPopArrow( r );
  188.   MoveTo( r.left+leftSlop, r.bottom-botSlop);
  189.   DrawString( curFont );
  190. }
  191.  
  192. static pascal void DrawPopUp1( DialogPtr theDialog, short theItem )
  193. {
  194.  #pragma unused( theDialog, theItem )
  195.  DrawPopUpX( popMenu1, &popUpBox1, fontChoice1 );
  196. }
  197.  
  198. static pascal void DrawPopUp2( DialogPtr theDialog, short theItem )
  199. {
  200.  #pragma unused( theDialog, theItem )
  201.  DrawPopUpX( popMenu2, &popUpBox2, fontChoice2 );
  202. }
  203.  
  204. /* BorderDefault draws a heavy border around the default ( OK ) button */
  205. static pascal void BorderDefault( WindowPtr dwind, short dinum )
  206. {
  207.   #pragma unused( dinum )
  208.   short itemtype;
  209.   Handle itemhandle;
  210.   Rect borderRect;
  211.   GetDialogItem( dwind, esdOK, &itemtype, &itemhandle, &borderRect );
  212.   InsetRect( &borderRect, -4, -4 );
  213.   PenSize( 3, 3 );
  214.   FrameRoundRect( &borderRect, 16, 16 );
  215.   PenSize( 1, 1 );
  216. }
  217.  
  218. /* Outliner draws a light border around the the user item */
  219. static pascal void Outliner( WindowPtr dwind, short dinum )
  220. { short itemtype;
  221.   Handle itemhandle;
  222.   Rect borderRect;
  223.   GetDialogItem( dwind, dinum, &itemtype, &itemhandle, &borderRect );
  224.   /* InsetRect( &borderRect, -4, -4 ); */
  225.   PenSize( 1, 1 );
  226.   FrameRoundRect( &borderRect, 16, 16 );
  227. }
  228.  
  229. /* util fcns. */
  230.  
  231. /* cursor to IBeam if it's over an active edit line, arrow if it's not */
  232. void IBeamIt( WindowPtr dwind )
  233. { Point mouseAt;
  234.   short itemtype;
  235.   Handle itemhandle;
  236.   Rect borderRect;
  237.   short itemNum;
  238.   /* first get the current edit line out of the dialog record */
  239.   itemNum = ((DialogPeek )dwind)->editField + 1; /* always stored 1 less */
  240.   GetDialogItem( dwind, itemNum, &itemtype, &itemhandle, &borderRect );
  241.   GetMouse( &mouseAt );
  242.   if( PtInRect( mouseAt, &borderRect ) )
  243.     SetCursor(&ibeam_cursor);
  244.   else
  245.     SetCursor(&qd.arrow);
  246. }
  247.  
  248. static void pseudoClick( DialogPtr dbox, short item )
  249. { short itemtype;
  250.   Rect itemrect;
  251.   Handle hC;
  252.   long tilticks;
  253.   GetDialogItem( dbox, item, &itemtype, &hC, &itemrect );
  254.   HiliteControl( (ControlHandle)hC, kControlButtonPart ); // inButton
  255.   Delay( 8, &tilticks );
  256.   HiliteControl( (ControlHandle)hC, false );
  257. }
  258.  
  259. static short apndMenu( MenuHandle hM, Str255 title, short itemno, Boolean check, Boolean realfont )
  260. {
  261.   AppendMenu( hM, title );
  262.   if( realfont ) SetItemStyle( hM, itemno, outline );
  263.   if( check )
  264.   { SetItemMark( hM, itemno, checkMark );
  265.     return itemno;
  266.   }
  267.   return 0;
  268. }
  269.  
  270. static MenuHandle sizeMenu( short id, short *ckitem, short fNum, short curSize )
  271. { MenuHandle hM;
  272.   Str255 oddSize;
  273.   short match = 0;
  274.   hM = NewMenu( id, "\p" );
  275.   match |= apndMenu( hM,  "\p9", 1, (curSize ==  9), RealFont( fNum,  9 ) );
  276.   match |= apndMenu( hM, "\p10", 2, (curSize == 10), RealFont( fNum, 10 ) );
  277.   match |= apndMenu( hM, "\p12", 3, (curSize == 12), RealFont( fNum, 12 ) );
  278.   match |= apndMenu( hM, "\p14", 4, (curSize == 14), RealFont( fNum, 14 ) );
  279.   match |= apndMenu( hM, "\p18", 5, (curSize == 18), RealFont( fNum, 18 ) );
  280.   match |= apndMenu( hM, "\p24", 6, (curSize == 24), RealFont( fNum, 24 ) );
  281.   if( match == 0 )
  282.   { NumToString( (long )curSize, oddSize );
  283.     InsertMenuItem( hM, oddSize, 0 );
  284.     InsertMenuItem( hM, "\p(-", 1 );
  285.     SetItemMark( hM, 1, checkMark );
  286.     if( RealFont( fNum, curSize ) ) SetItemStyle( hM, 1, outline );
  287.     *ckitem = 1;
  288.   }
  289.   else *ckitem = match;
  290.   return( hM );
  291. }
  292.  
  293. static short doPop( DialogPtr esd, MenuHandle popMenu, Rect popUpBox, short id, short oldChoice )
  294. {
  295.   #pragma unused( esd )
  296.   long chosen;
  297.   Point popLoc;
  298.   short newChoice;
  299.   InsertMenu( popMenu, -1 );
  300.   popLoc = topLeft(popUpBox);
  301.   LocalToGlobal( &popLoc );
  302.   CalcMenuSize( popMenu ); /* Work around Menu Mgr bug */
  303.   chosen = PopUpMenuSelect( popMenu, popLoc.v, popLoc.h, oldChoice );
  304.   DeleteMenu( id );
  305.   if( chosen != 0 )
  306.   { newChoice = LoWord(chosen);
  307.     if( newChoice != oldChoice )
  308.     { SetItemMark( popMenu, oldChoice, ' ' );
  309.       SetItemMark( popMenu, newChoice, checkMark );
  310.       EraseRect( &popUpBox );
  311.       return( newChoice );
  312.     }
  313.   }
  314.   return 0;
  315. }
  316.  
  317. /* filter proc */
  318.  
  319. #define kReturnKey 0x0D
  320. #define kEnterKey 0x03
  321. #define kEscKey 0x1B
  322. #define kTabKey 9
  323. enum  {
  324.     kBackSpace = 8,
  325.     kLeftArrow = 0x1C, kRightArrow, kUpArrow, kDownArrow,
  326.     kDeleteKey = 0x7F
  327. };
  328.  
  329. /* size menu selection => edit text box */
  330. static void doSize1( DialogPtr esd )
  331. { Rect tempRect;
  332.   short tempItem;
  333.   Handle tempHandle;
  334.   long tmp;
  335.   Str255 tStr;
  336.   GetDialogItem( esd, esdSize1Et, &tempItem, &tempHandle, &tempRect );
  337.   GetMenuItemText( popMenu3, sizeChoice3, tStr );
  338.   SetDialogItemText( tempHandle, tStr );
  339.   SelectDialogItemText( esd, esdSize1Et, 0, 32767 );
  340.   StringToNum( tStr, &tmp);
  341.   tsNewPri.tsSize = tmp;
  342. }
  343.  
  344. /* size menu selection => edit text box */
  345. static void doSize2( DialogPtr esd )
  346. { Rect tempRect;
  347.   short tempItem;
  348.   Handle tempHandle;
  349.   long tmp;
  350.   Str255 tStr;
  351.   GetDialogItem( esd, esdSize2Et, &tempItem, &tempHandle, &tempRect );
  352.   GetMenuItemText( popMenu4, sizeChoice4, tStr );
  353.   SetDialogItemText( tempHandle, tStr );
  354.   SelectDialogItemText( esd, esdSize2Et, 0, 32767 );
  355.   StringToNum( tStr, &tmp);
  356.   tsNewAlt.tsSize = tmp;
  357. }
  358.  
  359. /* font menu selection triggers update of size menu */
  360. static void doFont1( void )
  361. { Str255 tStr;
  362.   GetMenuItemText( popMenu1, fontChoice1, tStr );
  363.   GetFNum( tStr, &tsNewPri.tsFont );
  364.   if( popMenu3 ) DisposeHandle( (Handle )popMenu3 );
  365.   popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  366. }
  367.  
  368. /* font menu selection triggers update of size menu */
  369. static void doFont2( void )
  370. { Str255 tStr;
  371.   GetMenuItemText( popMenu2, fontChoice2, tStr );
  372.   GetFNum( tStr, &tsNewAlt.tsFont );
  373.   if( popMenu4 ) DisposeHandle( (Handle )popMenu4 );
  374.   popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  375. }
  376.  
  377. /* this function always returns a value between 1 and MAXFONTSIZE inclusive */
  378. /* an out of range number returns 8;
  379.    this is so font sizes and tab stops are reasonable */
  380. static long etToNum( DialogPtr dbox, short item )
  381. { short tempItem;
  382.   Rect tempRect;
  383.   Handle tempHandle;
  384.   long tmp;
  385.   Str255 tStr;
  386.   GetDialogItem( dbox, item, &tempItem, &tempHandle, &tempRect );
  387.   GetDialogItemText( tempHandle, tStr );
  388.   StringToNum( tStr, &tmp);
  389.   if( tmp > MAXFONTSIZE || tmp < 1 ) tmp = 8;
  390.   return tmp;
  391. }
  392.  
  393. /* update size menu if size edit text box changed */
  394. static void preSize1( DialogPtr esd )
  395. { long tmp;
  396.   tmp = etToNum( esd, esdSize1Et );
  397.   if( tsNewPri.tsSize != tmp )
  398.   { tsNewPri.tsSize = tmp;
  399.     if( popMenu3 ) DisposeHandle( (Handle )popMenu3 );
  400.     popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  401.   }
  402. }
  403.  
  404. /* update size menu if size edit text box changed */
  405. static void preSize2( DialogPtr esd )
  406. { long tmp;
  407.   tmp = etToNum( esd, esdSize2Et );
  408.   if( tsNewAlt.tsSize != tmp )
  409.   { tsNewAlt.tsSize = tmp;
  410.     if( popMenu4 ) DisposeHandle( (Handle )popMenu4 );
  411.     popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  412.   }
  413. }
  414.  
  415. pascal Boolean filterIt( DialogPtr esd, EventRecord *myDialogEvent, short *theDialogItem)
  416. { WindowPtr temp;
  417.   char theKey;
  418.   Boolean result = false;
  419.  
  420.   GetPort( &temp );
  421.   SetPort( esd );
  422.     
  423.   IBeamIt( esd ); /* make IBeam cursor when over the active edit line */
  424.     
  425.   /* do standard filtering for escape and return as OK and Cancel aliases */
  426.   /* invert the button in the dialog, so the user get's visual feedback */
  427.  
  428.   if ((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey))
  429.   { theKey = myDialogEvent->message & charCodeMask;
  430.     if( (myDialogEvent->modifiers & (cmdKey|controlKey|optionKey)) == 0 )
  431.     { switch( theKey )
  432.       { case kReturnKey:
  433.         case kEnterKey:
  434.             *theDialogItem = esdOK;
  435.             pseudoClick( esd, esdOK );
  436.           SetPort(temp);
  437.           result = true;
  438.           break;
  439.         case kEscKey:
  440.           *theDialogItem = esdCancel;
  441.           pseudoClick( esd, esdCancel );
  442.           SetPort(temp);
  443.           result = true;
  444.           break;
  445.         case kTabKey:
  446.         case kBackSpace:
  447.         case kLeftArrow:
  448.         case kRightArrow:
  449.         case kUpArrow:
  450.         case kDownArrow:
  451.         case kDeleteKey:
  452.             break;
  453.         default:
  454.           /* filter out non-numeric keys */
  455.           if( theKey < 0x30 || theKey > 0x39 )
  456.           { SysBeep( 1 );
  457.             SetPort( temp );
  458.             result = true;
  459.           }
  460.           break;
  461.       }
  462.     }
  463.   }
  464.   else if( myDialogEvent->what == mouseDown )
  465.   { Point mouseLoc;
  466.     short newChoice;
  467.     mouseLoc = ( myDialogEvent->where );
  468.     GlobalToLocal( &mouseLoc );
  469.     switch( newChoice = FindDialogItem( esd, mouseLoc ) + 1 )
  470.     { case esdFont1St:
  471.       case esdFont1Pu:
  472.         InvertRect( &promptBox1 );
  473.         newChoice = doPop( esd, popMenu1, popUpBox1, popMenuID1, fontChoice1 );
  474.         InvertRect( &promptBox1 );
  475.         if( newChoice != 0 )
  476.         { fontChoice1 = newChoice;
  477.           DrawPopUp1( esd, esdFont1Pu );
  478.           *theDialogItem = esdFont1Pu;
  479.           SetPort( temp );
  480.           result = true;
  481.         }
  482.         break;
  483.       case esdFont2St:
  484.       case esdFont2Pu:
  485.         InvertRect( &promptBox2 );
  486.         newChoice = doPop( esd, popMenu2, popUpBox2, popMenuID2, fontChoice2 );
  487.         InvertRect( &promptBox2 );
  488.         if( newChoice != 0 )
  489.         { fontChoice2 = newChoice;
  490.           DrawPopUp2( esd, esdFont2Pu );
  491.           *theDialogItem = esdFont2Pu;
  492.           SetPort( temp );
  493.           result = true;
  494.         }
  495.         break;
  496.       /* case esdSize2St:  not for size menu!? */
  497.       case esdSize1Pu:
  498.           SelectDialogItemText( esd, esdSize1Et, 0, 32767 );
  499.           preSize1( esd );
  500.         newChoice = doPop( esd, popMenu3, popUpBox3, popMenuID3, sizeChoice3 );
  501.         if( newChoice != 0 )
  502.         { sizeChoice3 = newChoice;
  503.           DrawPopUpSz( esd, esdSize1Pu );
  504.           *theDialogItem = esdSize1Pu;
  505.           SetPort( temp );
  506.           result = true;
  507.         }
  508.         break;
  509.       /* case esdSize2St:  not for size menu!? */
  510.       case esdSize2Pu:
  511.           SelectDialogItemText( esd, esdSize2Et, 0, 32767 );
  512.           preSize2( esd );
  513.         newChoice = doPop( esd, popMenu4, popUpBox4, popMenuID4, sizeChoice4 );
  514.         if( newChoice != 0 )
  515.         { sizeChoice4 = newChoice;
  516.           DrawPopUpSz( esd, esdSize2Pu );
  517.           *theDialogItem = esdSize2Pu;
  518.           SetPort( temp );
  519.           result = true;
  520.         }
  521.         break;
  522.     }
  523.   }
  524.   return( result );
  525. }
  526.  
  527. static void check( DialogPtr dbox, short item, Boolean mark )
  528. { ControlHandle hC;
  529.   short itemtype;
  530.   Rect itemrect;    
  531.   GetDialogItem( dbox, item, &itemtype, (Handle *)&hC, &itemrect);
  532.   SetControlValue( hC, mark );
  533. }
  534.  
  535. static void checks( DialogPtr dbox, short style, short offs )
  536. {
  537.   check( dbox, esdBold1Cb + offs, ( style & bold ) ? 1 : 0 );
  538.   check( dbox, esdItal1Cb + offs, ( style & italic ) ? 1 : 0 );
  539.   check( dbox, esdUndr1Cb + offs, ( style & underline ) ? 1 : 0 );
  540.   check( dbox, esdCond1Cb + offs, ( style & condense ) ? 1 : 0 );
  541.   check( dbox, esdExpd1Cb + offs, ( style & extend ) ? 1 : 0 );
  542.   /*
  543.   check( dbox, esdInvr1Cb + offs, ( style & bold ) ? 1 : 0 );
  544.   */
  545. }
  546.  
  547. short checklist[] = { bold, italic, condense, underline, 0x80, extend };
  548.  
  549. static short findFontItem( MenuHandle hM, short fontNum )
  550. { short result = 1;
  551.   short i, fn;
  552.   Str255 tStr;
  553.   for( i = CountMItems( hM ); i > 0; i-- )
  554.   { GetMenuItemText( hM, i, tStr );
  555.     GetFNum( tStr, &fn );
  556.     if( fn == fontNum ) return i;
  557.     if( fn == 0 ) result = i;
  558.   }
  559.   return result;
  560. }
  561.  
  562. /* get the item's rect & set the procPtr */
  563. static void initUserItem( DialogPtr esd, short item, Rect *pRect, UserItemUPP pProc )
  564. { short tempItem;
  565.   Handle tempHandle;
  566.   GetDialogItem( esd, item, &tempItem, &tempHandle, pRect );
  567.   SetDialogItem( esd, item, tempItem, (Handle )pProc, pRect );
  568. }
  569.  
  570. static void hosePops( void )
  571. {
  572.   if( popMenu1 ) DisposeHandle( (Handle )popMenu1 );
  573.   popMenu1 = 0;
  574.   if( popMenu2 ) DisposeHandle( (Handle )popMenu2 );
  575.   popMenu2 = 0;
  576.   if( popMenu3 ) DisposeHandle( (Handle )popMenu3 );
  577.   popMenu3 = 0;
  578.   if( popMenu4 ) DisposeHandle( (Handle )popMenu4 );
  579.   popMenu4 = 0;
  580. }
  581.  
  582. static void initPops( DialogPtr esd )
  583. { Str255 tStr;
  584.   short tempItem;
  585.   Rect tempRect;
  586.   Handle tempHandle;
  587.  
  588.   hosePops();
  589.   
  590.   SetPort( esd );
  591.   
  592.   popMenu1 = NewMenu( popMenuID1, "\p" );
  593.   AppendResMenu( popMenu1, 'FONT' );
  594.   fontChoice1 = findFontItem( popMenu1, tsNewPri.tsFont );
  595.   SetItemMark( popMenu1, fontChoice1, checkMark );
  596.   InvalRect( &popUpBox1 );
  597.     
  598.   popMenu2 = NewMenu( popMenuID2, "\p" );
  599.   AppendResMenu( popMenu2, 'FONT' );
  600.   fontChoice2 = findFontItem( popMenu2, tsNewAlt.tsFont );
  601.   SetItemMark( popMenu2, fontChoice2, checkMark );
  602.   InvalRect( &popUpBox2 );
  603.   
  604.   popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  605.   doSize1( esd );
  606.  
  607.   popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  608.   doSize2( esd );
  609.   
  610.   checks( esd, tsNewPri.tsFace,  0 );
  611.   checks( esd, tsNewAlt.tsFace, 10 );
  612.   
  613.   NumToString( (long )tabsNew, tStr );
  614.   GetDialogItem( esd, esdTabsEt, &tempItem, &tempHandle, &tempRect );
  615.   SetDialogItemText( tempHandle, tStr );
  616.   SelectDialogItemText( esd, esdTabsEt, 0, 32767 );
  617.   
  618.   NumToString( (long )wrapNew, tStr );
  619.   GetDialogItem( esd, esdWrapEt, &tempItem, &tempHandle, &tempRect );
  620.   SetDialogItemText( tempHandle, tStr );
  621.   SelectDialogItemText( esd, esdWrapEt, 0, 32767 );
  622.  
  623.   check( esd, esdAutoInd, autoIndNew );
  624. }
  625.  
  626. static suppinit = 0;
  627. ModalFilterUPP filterItUPP;
  628. UserItemUPP DrawPopUp1UPP;
  629. UserItemUPP DrawPopUp2UPP;
  630. UserItemUPP DrawPopUpSzUPP;
  631. UserItemUPP OutlinerUPP;
  632. UserItemUPP BorderDefaultUPP;
  633.  
  634. void eStyleDlg( eRec **hE /* , TextStyle *pri, TextStyle *alt */ )
  635. { DialogPtr esd = NULL;
  636.   short hitItem = 0;
  637.   short tempItem;
  638.   Rect tempRect;
  639.   Handle tempHandle;
  640.   long tmp1, tmp2, tmp3;
  641.  
  642.   if ( ! suppinit )
  643.   { filterItUPP = NewModalFilterProc(filterIt);
  644.     DrawPopUp1UPP  = NewUserItemProc(DrawPopUp1);
  645.     DrawPopUp2UPP  = NewUserItemProc(DrawPopUp2);
  646.     DrawPopUpSzUPP = NewUserItemProc(DrawPopUpSz);
  647.     OutlinerUPP    = NewUserItemProc(Outliner);
  648.     BorderDefaultUPP = NewUserItemProc(BorderDefault);
  649.     suppinit = 1;
  650.   }
  651.   
  652.   tsNewPri = (**hE).style[0];
  653.   tsNewAlt = (**hE).style[1];
  654.   tabsNew = (**hE).tabStops;
  655.   wrapNew = (**hE).wrap;
  656.   autoIndNew = (**hE).autoInd;
  657.  
  658.   /* Get a dialog box, and set up our useritems */
  659.   esd = GetNewDialog( esdID, NULL, (WindowPtr)(-1) );
  660.         
  661.   /* Find out where our useritems are, and set their item handles to be
  662.      a pointer to our popup-drawing or other special procedure */
  663.   GetDialogItem( esd, esdFont1St, &tempItem, &tempHandle, &promptBox1 ); /* get the title rect */
  664.   initUserItem( esd, esdFont1Pu, &popUpBox1, DrawPopUp1UPP ); /* universal header kludge 7Jun94 e */
  665.   GetDialogItem( esd, esdFont2St, &tempItem, &tempHandle, &promptBox2 ); /* get the title rect */
  666.   initUserItem( esd, esdFont2Pu, &popUpBox2, DrawPopUp2UPP ); /* universal header kludge 7Jun94 e */
  667.   initUserItem( esd, esdSize1Pu, &popUpBox3, DrawPopUpSzUPP ); /* universal header kludge 7Jun94 e */
  668.   initUserItem( esd, esdSize2Pu, &popUpBox4, DrawPopUpSzUPP ); /* universal header kludge 7Jun94 e */
  669.   initUserItem( esd, esdOutline1, &tempRect, OutlinerUPP ); /* universal header kludge 7Jun94 e */
  670.   initUserItem( esd, esdOutline2, &tempRect, OutlinerUPP ); /* universal header kludge 7Jun94 e */
  671.   initUserItem( esd, esdOutline3, &tempRect, OutlinerUPP ); /* universal header kludge 7Jun94 e */
  672.  
  673.   GetDialogItem( esd, esdOK,&tempItem, &tempHandle, &tempRect ); /* get the OK button's rect */
  674.   InsetRect( &tempRect, -4, -4);
  675.   SetDialogItem( esd, esdOKring, userItem+itemDisable, (Handle )BorderDefaultUPP, &tempRect);
  676.  
  677.   /* Get two menus containing the current set of fonts */
  678.   /* and two menus containing their corresponding sizes */
  679.   initPops( esd );
  680.   
  681.   check( esd, esdThisCb, 1 );
  682.   check( esd, esdPrefCb, 0 );    /* defaulted to off  --  16Jul92  e  */
  683.     
  684.   ShowWindow( (WindowPtr)esd );
  685.   DrawDialog( esd );
  686.   do
  687.   { ModalDialog( filterItUPP, &hitItem );
  688.     switch ( hitItem )
  689.     { case esdFont1Pu:
  690.         doFont1( );
  691.         break;
  692.       case esdFont2Pu:
  693.         doFont2( );
  694.         break;
  695.       case esdSize1Pu:
  696.           doSize1( esd );
  697.         break;
  698.       case esdSize2Pu:
  699.           doSize2( esd );
  700.         break;
  701.       case esdBold1Cb:
  702.       case esdItal1Cb:
  703.       case esdCond1Cb:
  704.       case esdUndr1Cb:
  705.       case esdInvr1Cb:
  706.       case esdExpd1Cb:
  707.         GetDialogItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  708.         tempItem = GetControlValue( (ControlHandle )tempHandle ) ^ 1;
  709.         if( tempItem == 0 )
  710.           tsNewPri.tsFace &= ~checklist[hitItem-esdBold1Cb];
  711.         else
  712.           tsNewPri.tsFace |=  checklist[hitItem-esdBold1Cb];
  713.         SetControlValue( (ControlHandle )tempHandle, tempItem);
  714.         break;
  715.       case esdBold2Cb:
  716.       case esdItal2Cb:
  717.       case esdCond2Cb:
  718.       case esdUndr2Cb:
  719.       case esdInvr2Cb:
  720.       case esdExpd2Cb:
  721.         GetDialogItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  722.         tempItem = GetControlValue( (ControlHandle )tempHandle ) ^ 1;
  723.         if( tempItem == 0 )
  724.           tsNewAlt.tsFace &= ~checklist[hitItem-esdBold2Cb];
  725.         else
  726.           tsNewAlt.tsFace |=  checklist[hitItem-esdBold2Cb];
  727.         SetControlValue( (ControlHandle )tempHandle, tempItem);
  728.         break;
  729.       case esdThisCb:
  730.       case esdPrefCb:
  731.       case esdAutoInd:
  732.         GetDialogItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  733.         tempItem = GetControlValue( (ControlHandle )tempHandle ) ^ 1;
  734.         SetControlValue( (ControlHandle )tempHandle, tempItem);
  735.         break;
  736.       case esdThisBt:
  737.         tsNewPri = (**hE).style[0];
  738.         tsNewAlt = (**hE).style[1];
  739.         tabsNew =  (**hE).tabStops;
  740.         wrapNew =  (**hE).wrap;
  741.         autoIndNew = (**hE).autoInd;
  742.         initPops( esd );
  743.         break;
  744.       case esdPrefBt:
  745.         tsNewPri = prefStylNormal;
  746.         tsNewAlt = prefStylHilite;
  747.         tabsNew  = prefTabs;
  748.         wrapNew  = prefWrap;
  749.         autoIndNew = prefAutoInd;
  750.         initPops( esd );
  751.         break;
  752.       case esdDfltBt:
  753.         tsNewPri = dfltStylNormal;
  754.         tsNewAlt = dfltStylHilite;
  755.         tabsNew  = dfltTabs;
  756.         wrapNew  = dfltWrap;
  757.         autoIndNew = dfltAutoInd;
  758.         initPops( esd );
  759.         break;
  760.     }
  761.   } while ( hitItem != esdOK && hitItem != esdCancel );
  762.   
  763.   if( hitItem == esdOK )
  764.   { tsNewPri.tsSize = etToNum( esd, esdSize1Et );
  765.     tsNewAlt.tsSize = etToNum( esd, esdSize2Et );
  766.     tmp1 = etToNum( esd, esdTabsEt );
  767.     tmp2 = etToNum( esd, esdWrapEt );
  768.     GetDialogItem( esd, esdAutoInd, &tempItem, &tempHandle, &tempRect);
  769.     tmp3 = GetControlValue( (ControlHandle )tempHandle );
  770.     GetDialogItem( esd, esdThisCb, &tempItem, &tempHandle, &tempRect);
  771.     if( GetControlValue( (ControlHandle )tempHandle ) )
  772.     { if( (**hE).tabStops != tmp1 )
  773.       { eTeSetTabStop( hE, (short )tmp1 );
  774.       }
  775.       if( (**hE).wrap != tmp2 )
  776.       { eTeSetWrap( hE, (short )tmp2 );
  777.       }
  778.       (**hE).autoInd = tmp3;
  779.       if(    tsNewPri.tsFont != (**hE).style[0].tsFont
  780.           || tsNewPri.tsSize != (**hE).style[0].tsSize
  781.           || tsNewPri.tsFace != (**hE).style[0].tsFace
  782.           || tsNewAlt.tsFont != (**hE).style[1].tsFont
  783.           || tsNewAlt.tsSize != (**hE).style[1].tsSize
  784.           || tsNewAlt.tsFace != (**hE).style[1].tsFace
  785.         )
  786.       { eTeSetStyles( hE, &tsNewPri, &tsNewAlt );
  787.       }
  788.     }
  789.     GetDialogItem( esd, esdPrefCb, &tempItem, &tempHandle, &tempRect);
  790.     if( GetControlValue( (ControlHandle )tempHandle ) )
  791.     { prefStylNormal = tsNewPri;
  792.       prefStylHilite = tsNewAlt;
  793.       prefTabs    = (short )tmp1;
  794.       prefWrap    = (short )tmp2;
  795.       prefAutoInd = (short )tmp3;
  796.       savePrefs( PREFS_FILENAME );  /*  16Jul92  e  */
  797.     }
  798.   }
  799.   hosePops();
  800.   if( esd ) DisposeDialog( esd );
  801. }
  802.  
  803. /* end of os_mac_eStyle.c */
  804.